package com.sky.demo.utils;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;

import android.content.Context;

public class Save {

	public static boolean savefile(Context context,String usernaem,String pass){
		
		try {
//			File filesDir = context.getFilesDir();
			File file = new File(context.getFilesDir(),"info.txt");
			FileOutputStream fos = new FileOutputStream(file);
			fos.write((usernaem+"##"+pass).getBytes());
			fos.close();
			return true;
		} catch (IOException e) {
			e.printStackTrace();
			return false;
		}
		
	}
	public static Map<String, String > get(Context context){
		File file = new File(context.getFilesDir(),"info.txt");
		try {
			FileInputStream fis  = new FileInputStream(file);
			BufferedReader br = new BufferedReader(new InputStreamReader(fis));
			String str = br.readLine();
			String[] infos = str.split("##");
			Map<String , String > map = new HashMap<>();
			map.put("username", infos[0]);
			map.put("pass", infos[0]);
			return map;
		} catch (IOException e) {
			e.printStackTrace();
			return null;
		}
		
	}
}
